//
//  SLBluetoothManager.h
//  SlockApp
//
//  Created by 凯朱 on 2024/8/6.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
typedef NS_ENUM(NSUInteger, SLEnumCreateFingerStatus) {
    SLEnumCreateFingerStatusNormal = 0, /*正常*/
    SLEnumCreateFingerStatusTimeout = 1, /*录入超时*/
    SLEnumCreateFingerStatusRepeat = 2, /*重复录入*/
    SLEnumCreateFingerStatusOverMax = 3, /*录入已满*/
    SLEnumCreateFingerStatusBad = 6, /*指纹图像不佳*/
    SLEnumCreateFingerStatusOverSize = 7 /*指纹录入重复面积过大*/
};

//封装蓝牙请求
typedef void(^SLSearchDeviceBlock)(BOOL isSuccess,CBPeripheral *peripheral,id data,NSString *errorMsg);
typedef void(^SLConnectDeviceBlock)(BOOL isSuccess,CBPeripheral *peripheral,id data,NSString *errorMsg);
typedef void(^SLBluetoothNotifyBlock)(NSString *commond,BOOL isSuccess,id data,NSString *errorMsg);
typedef void(^SLCreateFingerBlock)(NSString *result,NSString *curStep,NSString *accessId,SLEnumCreateFingerStatus code);
typedef void(^SLGetFingerDatasBlock)(BOOL isSuccess,NSArray <SLLockKeyModel *>*keyDatas);
typedef void(^SLBluetoothStatusBlock)(NSString *commond,id data);
typedef void(^SLBluetoothDataBlock)(id data);
typedef void(^SLUpdateFirmwareBlock)(BOOL isSuccess,CGFloat progress, NSString *errormsg);
typedef void(^SLDisConnectBlock)(void);

@interface SLBluetoothManager : NSObject
+(instancetype)sharedManager;
@property (nonatomic, strong)NSString *autoConnectDeviceNo;/*自动连接的设备No*/
@property (nonatomic, strong)CBPeripheral *curPeripheral;/*当前连接的蓝牙*/
@property (nonatomic, strong)SLLockModel *curClickLockModel;/*当前正在操作的蓝牙设备模型 - 非连接情况下*/
@property (nonatomic, strong)SLLockModel *curLockModel;/*当前连接的蓝牙设备模型*/
@property (nonatomic, assign)BOOL isSearching;/*正在搜索中*/
@property (nonatomic, assign)BOOL isConnecting;/*正在连接中*/

//开始搜索设备
-(void)startSearchDevice:(BOOL)isBridge finish:(SLSearchDeviceBlock)finish;

//开始搜索设备并且连接设备
-(void)startSearchDeviceAndConnect:(NSString *)deviceNo isBridge:(BOOL)isBridge finish:(SLConnectDeviceBlock)finish;

//停止搜索设备
-(void)stopSearchDevice;
//连接蓝牙
-(void)connectDevice:(CBPeripheral *)peripheral finish:(SLConnectDeviceBlock)finish;
//断开蓝牙连接
-(void)disConnectPeripheral;

//绑定设备
-(void)bindDeviceWith:(SLBluetoothNotifyBlock)finish;
//解绑设备
-(void)unBindDeviceWith:(SLBluetoothNotifyBlock)finish;

#pragma mark -
#pragma mark - ================<以下为业务层面接口封装 - 智锁>===============
/*
 同步设备时间
 */
-(void)sysncDeviceTime;

/*
 查询设备状态信息 - 温度，电量
 */
-(void)getDeviceStatusInfo:(SLBluetoothDataBlock)finish;

/*
 查询设备基本信息 - 设置/固件升级页面用到
 */
-(void)getDeviceBaseInfo:(SLBluetoothDataBlock)finish;

/*
 查询设备设置信息 - 设置页面用到
 */
-(void)getDeviceSettingInfo:(SLBluetoothDataBlock)finish;

/*
 开关锁命令
 type 00：蓝牙关锁 01：蓝牙开锁 02：远程关锁  03：远程开锁
 uid - 成员id 传10进制字符串 0-100（0x01~0x64）
 */
-(void)openLockWith:(NSString *)openType uid:(NSString *)uid finish:(SLBluetoothNotifyBlock)finish;

/*
 设置音量 0-静音 1-低 2-中 3-高
 */
-(void)setDeviceVoice:(NSInteger)voiceLevel finish:(SLBluetoothNotifyBlock)finish;

/*
 设置震动报警（防撬）
 yes-开启 no-关闭
 */
-(void)setVibrationAlarm:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 设置高温报警
 yes-开启 no-关闭
 */
-(void)setBurningAlarm:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 设置wifi开锁
 yes-开启 no-关闭
 */
-(void)setAllowWifiOpenModel:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 设置蓝牙开锁
 yes-开启 no-关闭
 */
-(void)setAllowBlueToothOpenModel:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 设置节能模式
 yes-开启 no-关闭
 */
-(void)setEnergyModel:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 设置双模开锁模式
 yes-开启 no-关闭
 */
-(void)setDbModel:(BOOL)open finish:(SLBluetoothNotifyBlock)finish;

/*
 添加指纹钥匙
 keyModel - 钥匙模型
 isManager - 是否是管理员
 */
-(void)addFingerAccessWith:(SLLockKeyModel *)keyModel isManager:(BOOL)isManager isCancel:(BOOL)isCancel finish:(SLCreateFingerBlock)finish;

/*
 修改钥匙 - 主要是修改该成员钥匙的时效性，不是指定的指纹
 keyModel - 钥匙模型
 isManager - 是否是管理员
 */
-(void)editFingerAccessWith:(SLLockKeyModel *)keyModel isManager:(BOOL)isManager finish:(SLBluetoothNotifyBlock)finish;

/*
 删除某个成员钥匙的指纹
 uid - 成员id
 accessId - 钥匙id，传空删除该成员钥匙下所有的指纹
 */
-(void)deleteUserFingerAccessWith:(NSString *)uid accessId:(NSString *)accessId finish:(SLBluetoothNotifyBlock)finish;

/*
 获取某成员id的钥匙数据
 uid - 成员id 不传则为所有的钥匙数据
 */
-(void)getFingerAccessDataWith:(NSString *)uid finish:(SLGetFingerDatasBlock)finish;

/*
 固件升级
 FirmwareData - 固件升级文件的data数据
 */
-(void)startUpdateFirmwareWith:(NSData *)FirmwareData finish:(SLUpdateFirmwareBlock)finish;

/*
 获取开锁日志信息
 */
-(void)getDeviceOpenLogDataWith:(SLBluetoothDataBlock)finish;

/*
 获取告警的日志信息
 */
-(void)getDeviceWarnLogDataWith:(SLBluetoothDataBlock)finish;

#pragma mark -
#pragma mark - ================<以下为业务层面接口封装 - 网关>===============
/*
 设置网关的wifi信息
 */
-(void)setGateWifiInfoWith:(NSString *)wifiName pswd:(NSString *)pswd finish:(SLBluetoothNotifyBlock)finish;

/*
 设置网关的MQTT主题
 */
-(void)setGateMqttThemeWith:(NSString *)theme finish:(SLBluetoothNotifyBlock)finish;

/*
 获取网关的wifi信息
 */
-(void)getGateWifiInfoWith:(SLBluetoothDataBlock)finish;

/*
 获取网关的MQTT主题
 */
-(void)getGateThemeInfoWith:(SLBluetoothDataBlock)finish;

/*
 网关连接wifi
 */
-(void)setGateStartConnectWifiWith:(SLBluetoothNotifyBlock)finish;

/*
 获取网关macaddress
 */
-(void)getGateMacAddressWith:(SLBluetoothNotifyBlock)finish;


+(NSData *)decryptData:(NSData *)data withKey:(NSData *)key;
@end


